#导入openai库
import configparser

from openai import OpenAI
import asyncio
import os
import edge_tts

from ai_server.audio_format.opus import Opus_Encode
from ai_server.llm.chatllm import ChatGLM_LLM
from ai_server.tts.edge import Edge_TTS
from ai_server.asr.fun_asr.fun_asr import Fun_Asr
from utils.util import Util

if __name__ == "__main__":
    config = Util.get_config()
    # llm = ChatGLM_LLM(config.get("LLM").get("ChatGLM"))
    # resource = llm.response("你好小智")
    # print(resource)
    # tts = Edge_TTS(config.get("TTS").get("Edge_tts"))
    # output_file = asyncio.run(tts.text_to_speech(resource, "./ai_server/audio_format/test.mp3"))
    # #windows 播放
    # os.system(f"start {output_file}")
    opus = Opus_Encode()
    opus_data, duration = opus.audio_to_opus("./ai_server/audio_format/test.mp3")
    output_path = opus.save_opus(opus_data,"./ai_server/audio_format/test.opus")
    opus_file = opus.load_opus(output_path)
    print("output",output_path)
    FunAsr = Fun_Asr(config.get("ASR").get("Fun_Asr"))
    asr_result = FunAsr.opus_to_text(opus_file)
    print(asr_result)

